// pages/subPages/withdraw/withdraw.js
const  app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    radio: '1',
    realName: '',
    mobile: '',
    maxMoney: '',
    money: '',
    zhifubaoNum: '',
    weixinNum: '',
    remark: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      maxMoney: options.commission
    })
  },


  onChange(event) {
    console.log(event);
    if(event.detail == this.data.radio) return
    this.setData({
      radio: event.detail,
      zhifubaoNum: '',
      weixinNum: '',
    });
  },
  submit(){
    const {realName, mobile, money, zhifubaoNum, weixinNum, remark, maxMoney, radio} = this.data;
    console.log(money + maxMoney);
    if(!realName) return  wx.showToast({ icon: 'none', title: '请填写用户名', })
    if(!mobile) return  wx.showToast({ icon: 'none', title: '请填写手机号码', })
    if(!money) return  wx.showToast({ icon: 'none', title: '请填写提现金额', })
    if(radio == 1 && !zhifubaoNum) return  wx.showToast({ icon: 'none', title: '请填写支付宝账号', })
    if(radio == 2 && !weixinNum) return  wx.showToast({ icon: 'none', title: '请填写微信账号', })
    if(Number(money) > Number(maxMoney)) return wx.showToast({ icon: 'none', title: '可提现金额不足', })
    wx.request({
      url: app.globalData.url + '/app/approveMoney',
      method: 'POST',
      data: {
        realName,
        mobile,
        money,
        zhifubaoNum,
        weixinNum,
        remark
      },
      header: {
        'Accept': 'application/json',
        'consumerId': app.globalData.userInfo.consumerId
      },
      success: function (res) {
        if (res.data.code == 200) { 
          const orderList = res.data.data.fans
          const order = {
            fansCount: res.data.data.fansCount,
            monthAddFansCount: res.data.data.fansCount,
            todayFansCount: res.data.data.todayFansCount,
          }
          that.setData({
            orderList,
            order
          })
          that.setSwiperHeight();
          that.data.loading = false;
        } else {
          wx.showToast({
            icon: 'none',
            title: res.data.msg,
          })
        }
      }
    })
  }
})